import 'package:flutter/material.dart';
import 'package:zhrs/Model/message.dart';
import 'package:zhrs/Utils/windowsSize.dart';
import 'package:zhrs/mainpage/webviewpage.dart';
class Service extends StatefulWidget
{

  Function reset;
  Service({this.rowcount=3,this.total=8,this.applicationfunctionlists,this.reset})
  {
    countcolum=(total/rowcount).toInt();
    if((total%rowcount)!=0)
    {
      countcolum=(total/rowcount).toInt()+1;
    }
    looptimes=new List<List<applicationfunctions> >();

    for(int i=0;i<countcolum;i++)
    {
      List<applicationfunctions> lists=new List<applicationfunctions>();
      for(int j=i*rowcount;j<i*rowcount+rowcount;j++)
      {
        if(j>=applicationfunctionlists.length)
          continue;
        lists.add(applicationfunctionlists[j]);
      }

      looptimes.add(lists);
    }


  }
  int total;
  int rowcount;
  int countcolum;
  List<applicationfunctions> applicationfunctionlists;
  List<List<applicationfunctions> > looptimes ;


  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _Service();
  }


}

class _Service extends State<Service>
{
  @override
  void initState() {
    // TODO: implement initState

    super.initState();
  }
  @override
  Widget build(BuildContext context) {

    // TODO: implement build
    return Column(
      children:
      widget.looptimes.map((val)
      {
        return Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: val.map((val){
              return new GestureDetector(
                  onTap: ()
                  {

                           if(val.url!=null)
                             {
                               widget.reset(url:val.url);
                             //  Navigator.push(context, new MaterialPageRoute(
                             //    builder :(context)=>new Webviewpage(url:val.url ,),
                             //  ));
                             }
                           else
                             {
                               showCupertinoDialogs(context, "建设中,敬请期待...");
                             }


                  },
                  child:  Container(
                    padding: EdgeInsets.only( top: 10 ),
                    child:  Column(
                      children: <Widget>[
                        new ClipRRect(
                          borderRadius: const BorderRadius.all(const Radius.circular(20)),
                          child:Container(
                           height:(windowsSize. mapViewWidth*0.96)/widget.rowcount-35,
                           width:(windowsSize. mapViewWidth*0.96)/widget.rowcount-35,
                            color: val.color,
                            child:new Image.network(//加载网络图片
                              val.imageUrl,
                              repeat:ImageRepeat.noRepeat,//图片重复方式
                            ),
                          ),
                        ),
                        Center(
                          child:Container(
                            width:(windowsSize. mapViewWidth*0.96)/widget.rowcount-19,
                            child:  Text(  val.description,style: TextStyle(fontSize: windowsSize.mapViewWidth/widget.rowcount*0.12, ),textAlign: TextAlign.center,),
                          ),
                        )
                      ],
                    ),
                  ),
                );
            }).toList()
        );
      }).toList()
    );
  }
}